import React, { Component } from "react";
import { withRouter, Link } from "react-router-dom";
import { Breadcrumb } from "antd";
@withRouter
export default class AppBreadcrumb extends Component {
	render() {
		const breadcrumbNameMap = {
			"/system/auth": "权限管理",
			"/system/role": "角色管理",
			"/system/user": "用户管理"
		};
		const { location } = this.props;
		const pathSnippets = location.pathname.split("/");
		pathSnippets.shift();
		const extraBreadcrumbItems = pathSnippets.map((_, index) => {
			const url = `/${pathSnippets.slice(0, index + 1).join("/")}`;
			return (
				<Breadcrumb.Item key={url}>
					<Link to={url}>
						{breadcrumbNameMap[url]}
						{index == pathSnippets.length - 1 ? (
							""
						) : (
							<span style={{ marginLeft: 5, marginRight: 5 }}>></span>
						)}
					</Link>
				</Breadcrumb.Item>
			);
		});
		const breadcrumbItems = [
			<Breadcrumb.Item key="home">
				<Link to="/home">首页</Link>
			</Breadcrumb.Item>
		].concat(extraBreadcrumbItems);
		return (
			<Breadcrumb className="admin-layout-breadcrumb" separator={""}>
				{breadcrumbItems}
			</Breadcrumb>
		);
	}
}
